<p><?= $this->Html->link("&laquo; Nazad na listu prodavnica", "/prodavnice", array('escape'=>false)) ?></p>

<?= $this->Form->create("Store", array("url"=>"/prodavnice/sacuvaj", "class"=>"entity-form")) ?>
	
	<?= $this->Form->hidden("id", array("value"=>@$store['Store']['id'])) ?>
	
	<?= $this->Form->label('active', 'Aktivna?') ?>
	<?= $this->Form->checkbox('active', array('value'=>1, 'checked'=>(int)@$store['Store']['active']>0)) ?>
	
	<?= $this->Form->label('client_id', 'Klijent:') ?>
	<?= $this->Form->select('client_id', $clients, array('value'=>@$store['Store']['client_id'], 'empty'=>'---'))?>
	
	<?= $this->Form->label('name', 'Naziv:') ?>
	<?= $this->Form->text('name', array('value'=>@$store['Store']['name'])) ?>

	<?= $this->Form->label('city', 'Grad:') ?>
	<?= $this->Form->text('city', array('value'=>@$store['Store']['city'])) ?>

	<?= $this->Form->label('township', 'Opština:') ?>
	<?= $this->Form->text('township', array('value'=>@$store['Store']['township'])) ?>
	
	<?= $this->Form->label('address', 'Adresa:') ?>
	<?= $this->Form->text('address', array('value'=>@$store['Store']['address'], 'class'=>'large')) ?>
	
	<?= $this->Form->label('phone', 'Telefon:') ?>
	<?= $this->Form->text('phone', array('value'=>@$store['Store']['phone'], 'class'=>'large')) ?>
	
	<hr>
	<? if(empty($store['Contact'])) {
		$store['Contact'] = array(
			array(
				'id'	=> '',
				'type'	=> '',
				'name'	=> '',
				'phone'	=> '',
				'email'	=> ''
			)
		);
	}?>
	<?= $this->Form->label('contacts', 'Kontakti:') ?>
	<div class="value multi-inputs" id="store_contacts">
		<? foreach($store['Contact'] as $k=>$contact): ?>
		<div class="item">
			<?= $this->Form->hidden("Contact.{$k}.id", array("value"=>$contact['id'])) ?>
			<?= $this->Form->select("Contact.{$k}.type", $contact_types, array("value"=>$contact['type'])) ?>
			<?= $this->Form->text("Contact.{$k}.name", array("value"=>$contact['name'], 'placeholder'=>'Ime...')) ?>
			<?= $this->Form->text("Contact.{$k}.phone", array("value"=>$contact['phone'], 'placeholder'=>'Telefon...')) ?>
			<?= $this->Form->text("Contact.{$k}.email", array("value"=>$contact['email'], 'placeholder'=>'E-mail...')) ?>
		</div>
		<? endforeach; ?>
	</div>
	
	<?= $this->Form->submit("Sačuvaj", array('div'=>false))?>
<?= $this->Form->end() ?>

<script type="text/javascript">

function store_contacts_onAdd(newItem) {
	newItem.find("input[type=hidden]").eq(0).val('');
}

function store_contacts_onDelete(deletedItem) {
	console.log(param);
}

</script>